package com.my.juc.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author zhupanlin
 * @version 1.0
 * @description: TODO
 * @date 2024/3/6 16:12
 */
public class ThreadPoolDemo1 {

    public static void main(String[] args) {
        // 一池五线程
        ExecutorService threadPool1 = Executors.newFixedThreadPool(5);
        
        // 一池一线程
        ExecutorService threadPool2 = Executors.newSingleThreadExecutor();
        
        // 一池可扩容线程
        ExecutorService threadPool3 = Executors.newCachedThreadPool();

        // 10个请求
        try {
            for (int i = 0; i < 20; i++) {
                // 执行
                threadPool3.execute(() -> {
                    System.out.println(Thread.currentThread().getName() + " 正在执行");
                });
            }
        } finally {
            // 关闭线程池
            threadPool3.shutdown();
        }

    }
    
}
